package controllers.power.admin;

import helper.GlobalConfig;
import models.admin.AdminOperate;
import org.apache.commons.lang.StringUtils;
import play.modules.paginate.JPAExtPaginator;
import play.mvc.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by youliangcheng on 17/5/24.
 */
public class AdminOperateCtrl extends Controller {
    public static void adminOperateList(Integer pageNumber,
                                        Long id,
                                        String filterKey,
                                        String name) {
        pageNumber = pageNumber == null ? 1 : pageNumber;
        Map<String, Object> searchMap = new HashMap<>();
        if (id != null)
            searchMap.put("id", id);

        if (StringUtils.isNotBlank(name))
            searchMap.put("name", "%" + name + "%");

        if (StringUtils.isNotBlank(filterKey))
            searchMap.put("name", "%" + filterKey + "%");

        JPAExtPaginator<AdminOperate> resultPage = AdminOperate.findByCondition(searchMap, "id", pageNumber, GlobalConfig.PAGE_SIZE);
        render(resultPage, pageNumber);

    }

}
